<?php
namespace Admin\Controller;
use Think\Controller;
class PublicController extends Controller {
    //用户登录
	public function login(){
        //实例化类模型
        $userModel=D("User");
        if(IS_POST){
            //验证绑定
            $captcha=I("post.captcha");
            $Verify = new \Think\Verify();
            if(!$Verify->check($captcha)){
                $this->error("验证码错误");
            }
            //判断用户登录是否成功
            if($userModel->create($_POST,4)){
                $status=$userModel->checkLogin(I('post.username'),I('post.password'));
                if($status===true){
                    $this->redirect('Index/index');
                }else{
                    $this->error("登录失败");
                }
            }else{
                $this->error($userModel->getError());
            }
        }
        //渲染模板
        $this->display();
    }
    //用户退出
    public function logout(){
        session(null);
        $this->redirect('Public/login');
    }
    //验证码
    public function captcha(){
        $config =    array(    
        'fontSize' => 15,    // 验证码字体大小    
        'length'   => 4,     // 验证码位数
        'codeSet'  => '123456789',  
        'useNoise' => false, // 关闭验证码杂点
        );
        $Verify = new \Think\Verify($config);
        echo $Verify->entry();
    }

}